// 在页面中定义插屏广告
let interstitialAd = null
import {
	BookModel
} from "../../models/book.js";

import config from "../../utils/config"
let bookModel = new BookModel()

Page({
	data: {
		searchPanel: false,
		books: Object,
		more: false,
		books: [], //图书列表
		appName: config.appName,
		isAd:config.isAd
	},
	async onLoad(options) {
		// 在页面onLoad回调事件中创建插屏广告实例
		if (wx.createInterstitialAd) {
			interstitialAd = wx.createInterstitialAd({
				adUnitId: 'adunit-c41d7d7535a297d5'
			})
			interstitialAd.onLoad(() => {})
			interstitialAd.onError((err) => {})
			interstitialAd.onClose(() => {})
		}

		wx.showLoading()
		var result = await bookModel.getAll();

		this.setData({
			books: result.data
		})
		wx.hideLoading()
	},
	onShow() {
		// 在适合的场景显示插屏广告
		if (interstitialAd) {
			interstitialAd.show().catch((err) => {
				console.error(err)
			})
		}
	},

	onActivateSearch: function (event) {
		this.setData({
			searchPanel: true
		})
	},
	onCancel: function (event) {
		this.setData({
			searchPanel: false
		})
	},

	onShareAppMessage() {

	}

})